package com.shiliao.app.activity.interlocution.dialog;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.shiliao.app.R;
import com.shiliao.app.activity.interlocution.entity.InterlocutionEntity;
import com.shiliao.app.activity.interlocution.ui.CommonProblemDetailActivity;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.ui.dilaog.AnimationType;
import com.yimei.framework.ui.dilaog.YimeiBaseDialog;
import com.yimei.framework.util.LogUtil;

import java.util.List;

/**
 * Created by yinzhiqiang on 2017/12/8.
 */

public class SimilarQuestionDialog extends YimeiBaseDialog implements SimilarQuestionAdapter.CheckQuestion {
    private ImageView close;
    private RecyclerView recyclerView;
    private TextView newquestion;
    private TextView oldquestion;
    private SimilarQuestionAdapter adapter;
//    private List<InterlocutionEntity> entities;

    /**
     * 构造函数.
     *
     * @param activity context
     */
    public SimilarQuestionDialog(Activity activity, List<InterlocutionEntity> entities) {
        super(activity);
//        this.entities=entities;
        mContainerView = getLayoutInflater().inflate(R.layout.popwindow_question_sel, null);
        close = (ImageView) mContainerView.findViewById(R.id.iv_close);
        recyclerView = (RecyclerView) mContainerView.findViewById(R.id.question_lv);
        newquestion = (TextView) mContainerView.findViewById(R.id.btn_newquestion);
        oldquestion = (TextView) mContainerView.findViewById(R.id.btn_oldquestion);
        mWindow.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER);
        mWindow.setWindowAnimations(mAnimations[AnimationType.TOAST_FADE
                .getValue()]);
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        recyclerView.setLayoutManager(new LinearLayoutManager(activity));
//        recyclerView.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL));
        adapter = new SimilarQuestionAdapter(activity, R.layout.item_similar_question, entities, this);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void show(boolean isAutoDismiss) {
        super.show(isAutoDismiss);
        WindowManager.LayoutParams params = mWindow.getAttributes();
        WindowManager windowManager = mActivity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        params.width = (int) (display.getWidth() * 0.9);
//        mWindow.setBackgroundDrawableResource(R.drawable);
        mWindow.setAttributes(params);
    }

    @Override
    public void clickCheck(final String position) {
        LogUtil.e("yzq", position + ".........");
        oldquestion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.e("yzq", position + ".........");
                Intent intent = new Intent(mActivity, CommonProblemDetailActivity.class);
                intent.putExtra("url", YMServerUtil.COMMON_PROBLEM_COTURL + position);
                mActivity.startActivity(intent);
                dismiss();
            }
        });
    }

    public void reqNewQuestion(View.OnClickListener clickListener) {
        newquestion.setOnClickListener(clickListener);
    }
}
